package mwn.droidbus.elements;

import java.util.ArrayList;

import com.google.android.maps.GeoPoint;

/**
 * The Class BusStop.
 * Represents a bus stop location in the world. 
 */
public class BusStop {

	/** The stop id. */
	private String stopID;
	
	/** The name. */
	private String name;
	
	/** The coordinates. */
	private GeoPoint coordinates;

	/** The routes that stop at this bus stop e.g. 861 or .. */
	private ArrayList<Route> routes;
	
	/**
	 * Instantiates a new bus stop.
	 *
	 * @param stopID the stop id
	 * @param name the name
	 * @param latitude the latitude
	 * @param longitude the longitude
	 */
	public BusStop(String stopID, String name, GeoPoint p) {//int latitude, int longitude) {
		this.name = name;
		this.coordinates = p;
		//this.coordinates = new GeoPoint(latitude, longitude);
		this.stopID = stopID;
	}
	
	public BusStop(String stopID, String name, double x, double y) {
		this.name = name;
		this.coordinates = degreesToGeoPoint(x,y);
		this.stopID = stopID;
	}
	
	public GeoPoint degreesToGeoPoint(double lat, double lon) {
		Double latitude = lat * 1000000;
		Double longitude = lon * 1000000;

		int glat = latitude.intValue();
		int glon = longitude.intValue();

		return new GeoPoint(glat,glon);
	}
	
	public BusStop(String stopID, String name, GeoPoint p, Route r) {//int latitude, int longitude, Route r) {
		this(stopID, name, p);
		routes.add(r);
	}
	
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return stopID + " " + name + " [" + coordinates.getLatitudeE6() + "," + coordinates.getLongitudeE6() + "]";
	}
	
	/**
	 * Find if a bus route stops at this stop
	 * Use this over routes.contains()
	 * @param route the route
	 * @return true, if a particular route stops here
	 */
	public boolean stopsHere(Route route) {
		for (Route thisRoute : routes) {
			if (thisRoute.getRouteID().equals(route.getRouteID())) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Gets the stop id.
	 *
	 * @return the stop id
	 */
	public String getStopID() {
		return stopID;
	}

	/**
	 * Sets the stop id.
	 *
	 * @param stopID the new stop id
	 */
	public void setStopID(String stopID) {
		this.stopID = stopID;
	}

	/**
	 * Gets the name.
	 *
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the name.
	 *
	 * @param name the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the coordinates.
	 *
	 * @return the coordinates
	 */
	public GeoPoint getCoordinates() {
		return coordinates;
	}

	/**
	 * Sets the coordinates.
	 *
	 * @param coordinates the new coordinates
	 */
	public void setCoordinates(GeoPoint coordinates) {
		this.coordinates = coordinates;
	}

	/**
	 * Gets the routes.
	 *
	 * @return the routes
	 */
	public ArrayList<Route> getRoutes() {
		return routes;
	}

	/**
	 * Sets the routes.
	 *
	 * @param routes the new routes
	 */
	public void setRoutes(ArrayList<Route> routes) {
		this.routes = routes;
	}
	
}
